package sctu.edu.java.year2016.team01.OurTeamProject.subroutine;

import sctu.edu.java.year2016.team01.OurTeamProject.subroutine.Read;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Zero on 2016/6/28.
 */
public class Solution {

    public void solution() {


        Read read = new Read();
        String path = "src\\main\\java\\sctu\\edu\\java\\year2016\\team01\\OurTeamProject";
        JFrame f = new JFrame();
        f.setLayout(null);
        f.setTitle("功能列表");
        f.setBounds(800, 300, 800, 600);
        Container con = f.getContentPane();
        JPanel pan = new JPanel();

        JLabel title = new JLabel("请选择解决的问题:");
        title.setFont(new Font("宋体", Font.BOLD, 21));
        title.setForeground(Color.white);
        title.setBounds(150, 200, 300, 40);


        ImageIcon background = new ImageIcon(path + "\\背景.png");
        JLabel label = new JLabel(background);
        label.setBounds(0, 0, 800, 600);
        JPanel imagePanel = (JPanel) f.getContentPane();
        imagePanel.setOpaque(false);
        f.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));


        JButton problem1 = new JButton("A.蓝屏");
        problem1.setFont(new Font("宋体", Font.BOLD, 19));
        problem1.setContentAreaFilled(false);
        problem1.setForeground(Color.white);
        problem1.setBounds(170, 250, 140, 30);

        JButton problem2 = new JButton("B.无法上网");
        problem2.setFont(new Font("宋体", Font.BOLD, 19));
        problem2.setContentAreaFilled(false);
        problem2.setForeground(Color.white);
        problem2.setBounds(170, 290, 140, 30);

        JButton problem3 = new JButton("C.电脑卡顿");
        problem3.setFont(new Font("宋体", Font.BOLD, 19));
        problem3.setContentAreaFilled(false);
        problem3.setForeground(Color.white);
        problem3.setBounds(170, 330, 140, 30);

        JButton problem4 = new JButton("D.其他");
        problem4.setFont(new Font("宋体", Font.BOLD, 19));
        problem4.setContentAreaFilled(false);
        problem4.setForeground(Color.white);
        problem4.setBounds(170, 370, 140, 30);



        problem1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {


                try {

                    read.solution("problem1.txt");
                    f.dispose();

                } catch (Exception e1) {
                    e1.printStackTrace();
                }


            }
        });


        problem2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {


                try {

                    read.solution("problem2.txt");
                    f.dispose();

                } catch (Exception e1) {
                    e1.printStackTrace();
                }


            }
        });



        problem3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {




                try {

                    read.solution("problem3.txt");
                    f.dispose();

                } catch (Exception e1) {
                    e1.printStackTrace();
                }


            }
        });


        problem4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {




                try {

                    read.solution("problem4.txt");
                    f.dispose();

                } catch (Exception e1) {
                    e1.printStackTrace();
                }


            }
        });


        f.getContentPane().add(title);
        f.getContentPane().add(problem1);
        f.getContentPane().add(problem2);
        f.getContentPane().add(problem3);
        f.getContentPane().add(problem4);
        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        con.add(pan);
        f.setVisible(true);

    }
}
